63A - Sinking Ship - CodeForces Solution


implementation sortings strings *900

Please click on ads to support us..

Python Code:

n=int(input())
l=[]
n1=0n2=0n3=0for i in range(n):
    b=[a for a in input().split()]
    if b[1]=='rat':
        l.insert(n1,b[0])
        n1+=1
        n2+=1
        n3+=1
    elif b[1]=='woman' or b[1]=='child':
        l.insert(n2,b[0])
        n2+=1
        n3+=1
    elif b[1]=='captain':
        l.append(b[0])
    else:
        l.insert(n3,b[0])
        n3+=1
print('\n'.join(l))

C++ Code:

/* 
    author : Antar chandra Nath
    
*/
 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
#define fast        ios::sync_with_stdio(0);cin.tie(0);cin.tie(0);
#define endl        "\n"
#define pb          push_back
#define po          pop_back
#define sz(x)       x.size()
#define all(x)      x.begin(), x.end()
#define fi          first 
#define se          second 
#define cn          cin >> 
#define co          cout <<
#define rep(i,n)    for(int i=0;i<n;i++)
#define per(i,n)    for(int i=n-1;i>=0;i--)
#define loop(i,j,n) for(int i=j;i<=n;i++)
#define vi          vector<int>
#define vvi         vector<vector<int>>
#define yes         cout << "YES" << endl
#define no          cout << "NO" << endl
#define mci         map<char, int> 
#define mii         map<int, int>
#define pi          pair<int, int>
#define pll         pair<ll, ll>
 
int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
const int maxn = 1e5 + 1;
const int mm = 1e9 + 9;
const ll mmm = 1e18 + 18;
ll gcd(ll a, ll b) {return __gcd(a, b);}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b);}
  
void solve(){
    int n;
    cin >> n;
    vector<string> a(n), b(n);
    vector<string> v = {"rat", "woman", "man", "captain"};
    map<string, vector<string> > mp;
    rep(i, n){
        cin >> a[i] >> b[i];
        if(b[i] == "woman" or b[i] == "child")
            mp["woman"].pb(a[i]);
        else
            mp[b[i]].pb(a[i]);
    }

    rep(i, 4){
        rep(j, mp[v[i]].size()){
            cout << mp[v[i]][j] << endl;
        }
    }
    
    

    return;
}
 
int main(){
    fast;
    int t(1);
    // cn t;
    while(t--){
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1064B - Equations of Mathematical Magic
384A - Coder
1738B - Prefix Sum Addicts
1352D - Alice Bob and Candies
1316D - Nash Matrix
1548B - Integers Have Friends
348A - Mafia
315B - Sereja and Array
204A - Little Elephant and Interval
385B - Bear and Strings
114C - Grammar Lessons
1427A - Avoiding Zero
583A - Asphalting Roads
1358B - Maria Breaks the Self-isolation
828A - Restaurant Tables
1735A - Working Week
1735D - Meta-set
1735B - Tea with Tangerines
1735C - Phase Shift
1321C - Remove Adjacent
281B - Nearest Fraction
1043A - Elections
1598C - Delete Two Elements
1400C - Binary String Reconstruction
1734D - Slime Escape
1499A - Domino on Windowsill
991A - If at first you don't succeed
1196C - Robot Breakout
373A - Collecting Beats is Fun
965A - Paper Airplanes